package com.example.calculator;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
	
	int result;
	int temp;
	
	EditText resultText;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		resultText = (EditText) findViewById(R.id.result);
		
		Button btn0 = (Button)findViewById(R.id.btn0);
		Button btn1 = (Button)findViewById(R.id.btn1);
		Button btn2 = (Button)findViewById(R.id.btn2);
		Button btn3 = (Button)findViewById(R.id.btn3);
		Button btn4 = (Button)findViewById(R.id.btn4);
		Button btn5 = (Button)findViewById(R.id.btn5);
		Button btn6 = (Button)findViewById(R.id.btn6);
		Button btn7 = (Button)findViewById(R.id.btn7);
		Button btn8 = (Button)findViewById(R.id.btn8);
		Button btn9 = (Button)findViewById(R.id.btn9);
		Button btnPlus = (Button)findViewById(R.id.btnPlus);
		Button btnEqual = (Button)findViewById(R.id.btnEqual);

		btn0.setOnClickListener(btnsOnClickListener);
		btn1.setOnClickListener(btnsOnClickListener);
		btn2.setOnClickListener(btnsOnClickListener);
		btn3.setOnClickListener(btnsOnClickListener);
		btn4.setOnClickListener(btnsOnClickListener);
		btn5.setOnClickListener(btnsOnClickListener);
		btn6.setOnClickListener(btnsOnClickListener);
		btn7.setOnClickListener(btnsOnClickListener);
		btn8.setOnClickListener(btnsOnClickListener);
		btn9.setOnClickListener(btnsOnClickListener);
		btn0.setOnClickListener(btnsOnClickListener);
		btnPlus.setOnClickListener(btnsOnClickListener);
		btnEqual.setOnClickListener(btnsOnClickListener);
		
		
	}

	OnClickListener btnsOnClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.btn0:
				temp = 0;
				resultText.setText(Integer.toString(temp));
				break;
			case R.id.btn1:
				temp = 1;
				resultText.setText(Integer.toString(temp));
				break;
			case R.id.btn2:
				temp = 2;
				resultText.setText(Integer.toString(temp));
				break;
			case R.id.btn3:
				temp = 3;
				resultText.setText(Integer.toString(temp));
				break;
			case R.id.btn4:
				temp = 4;
				resultText.setText(Integer.toString(temp));
				break;
			case R.id.btn5:
				temp = 5;
				resultText.setText(Integer.toString(temp));
				break;
			case R.id.btn6:
				temp = 6;
				resultText.setText(Integer.toString(temp));
				break;
			case R.id.btn7:
				temp = 7;
				resultText.setText(Integer.toString(temp));
				break;
			case R.id.btn8:
				temp = 8;
				resultText.setText(Integer.toString(temp));
				break;
			case R.id.btn9:
				temp = 9;
				resultText.setText(Integer.toString(temp));
				break;
			case R.id.btnPlus:
				result = temp;
				temp = 0;
				break;
			case R.id.btnEqual:
				result += temp;
				resultText.setText(Integer.toString(result));
				break;
			}
		}
	};
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
